#include <stdio.h>

#define IMG_H 512
#define IMG_W 512
#define THRES 128

typedef unsigned char byte;

static int elut[255][4] = {
    {-56, -8, -40, -24},
    {-55, -8, -39, -24},
    {-55, -8, -39, -23},
    {-54, -8, -39, -23},
    {-54, -8, -38, -23},
    {-53, -8, -38, -23},
    {-53, -8, -38, -23},
    {-52, -7, -37, -22},
    {-52, -7, -37, -22},
    {-52, -7, -37, -22},
    {-51, -7, -37, -22},
    {-51, -7, -36, -22},
    {-50, -7, -36, -22},
    {-50, -7, -36, -21},
    {-49, -7, -35, -21},
    {-49, -7, -35, -21},
    {-49, -7, -35, -21},
    {-48, -7, -34, -21},
    {-48, -7, -34, -20},
    {-47, -7, -34, -20},
    {-47, -7, -33, -20},
    {-46, -7, -33, -20},
    {-46, -7, -33, -20},
    {-45, -6, -32, -19},
    {-45, -6, -32, -19},
    {-45, -6, -32, -19},
    {-44, -6, -32, -19},
    {-44, -6, -31, -19},
    {-43, -6, -31, -19},
    {-43, -6, -31, -18},
    {-42, -6, -30, -18},
    {-42, -6, -30, -18},
    {-42, -6, -30, -18},
    {-41, -6, -29, -18},
    {-41, -6, -29, -17},
    {-40, -6, -29, -17},
    {-40, -6, -28, -17},
    {-39, -6, -28, -17},
    {-39, -6, -28, -17},
    {-38, -5, -27, -16},
    {-38, -5, -27, -16},
    {-38, -5, -27, -16},
    {-37, -5, -27, -16},
    {-37, -5, -26, -16},
    {-36, -5, -26, -16},
    {-36, -5, -26, -15},
    {-35, -5, -25, -15},
    {-35, -5, -25, -15},
    {-35, -5, -25, -15},
    {-34, -5, -24, -15},
    {-34, -5, -24, -14},
    {-33, -5, -24, -14},
    {-33, -5, -23, -14},
    {-32, -5, -23, -14},
    {-32, -5, -23, -14},
    {-31, -4, -22, -13},
    {-31, -4, -22, -13},
    {-31, -4, -22, -13},
    {-30, -4, -22, -13},
    {-30, -4, -21, -13},
    {-29, -4, -21, -13},
    {-29, -4, -21, -12},
    {-28, -4, -20, -12},
    {-28, -4, -20, -12},
    {-28, -4, -20, -12},
    {-27, -4, -19, -12},
    {-27, -4, -19, -11},
    {-26, -4, -19, -11},
    {-26, -4, -18, -11},
    {-25, -4, -18, -11},
    {-25, -4, -18, -11},
    {-24, -3, -17, -10},
    {-24, -3, -17, -10},
    {-24, -3, -17, -10},
    {-23, -3, -17, -10},
    {-23, -3, -16, -10},
    {-22, -3, -16, -10},
    {-22, -3, -16, -9},
    {-21, -3, -15, -9},
    {-21, -3, -15, -9},
    {-21, -3, -15, -9},
    {-20, -3, -14, -9},
    {-20, -3, -14, -8},
    {-19, -3, -14, -8},
    {-19, -3, -13, -8},
    {-18, -3, -13, -8},
    {-18, -3, -13, -8},
    {-17, -2, -12, -7},
    {-17, -2, -12, -7},
    {-17, -2, -12, -7},
    {-16, -2, -12, -7},
    {-16, -2, -11, -7},
    {-15, -2, -11, -7},
    {-15, -2, -11, -6},
    {-14, -2, -10, -6},
    {-14, -2, -10, -6},
    {-14, -2, -10, -6},
    {-13, -2, -9, -6},
    {-13, -2, -9, -5},
    {-12, -2, -9, -5},
    {-12, -2, -8, -5},
    {-11, -2, -8, -5},
    {-11, -2, -8, -5},
    {-10, -1, -7, -4},
    {-10, -1, -7, -4},
    {-10, -1, -7, -4},
    {-9, -1, -7, -4},
    {-9, -1, -6, -4},
    {-8, -1, -6, -4},
    {-8, -1, -6, -3},
    {-7, -1, -5, -3},
    {-7, -1, -5, -3},
    {-7, -1, -5, -3},
    {-6, -1, -4, -3},
    {-6, -1, -4, -2},
    {-5, -1, -4, -2},
    {-5, -1, -3, -2},
    {-4, -1, -3, -2},
    {-4, -1, -3, -2},
    {-3, 0, -2, -1},
    {-3, 0, -2, -1},
    {-3, 0, -2, -1},
    {-2, 0, -2, -1},
    {-2, 0, -1, -1},
    {-1, 0, -1, -1},
    {-1, 0, -1, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {1, 0, 1, 0},
    {1, 0, 1, 1},
    {2, 0, 1, 1},
    {2, 0, 2, 1},
    {3, 0, 2, 1},
    {3, 0, 2, 1},
    {4, 1, 3, 2},
    {4, 1, 3, 2},
    {4, 1, 3, 2},
    {5, 1, 3, 2},
    {5, 1, 4, 2},
    {6, 1, 4, 2},
    {6, 1, 4, 3},
    {7, 1, 5, 3},
    {7, 1, 5, 3},
    {7, 1, 5, 3},
    {8, 1, 6, 3},
    {8, 1, 6, 4},
    {9, 1, 6, 4},
    {9, 1, 7, 4},
    {10, 1, 7, 4},
    {10, 1, 7, 4},
    {11, 2, 8, 5},
    {11, 2, 8, 5},
    {11, 2, 8, 5},
    {12, 2, 8, 5},
    {12, 2, 9, 5},
    {13, 2, 9, 5},
    {13, 2, 9, 6},
    {14, 2, 10, 6},
    {14, 2, 10, 6},
    {14, 2, 10, 6},
    {15, 2, 11, 6},
    {15, 2, 11, 7},
    {16, 2, 11, 7},
    {16, 2, 12, 7},
    {17, 2, 12, 7},
    {17, 2, 12, 7},
    {18, 3, 13, 8},
    {18, 3, 13, 8},
    {18, 3, 13, 8},
    {19, 3, 13, 8},
    {19, 3, 14, 8},
    {20, 3, 14, 8},
    {20, 3, 14, 9},
    {21, 3, 15, 9},
    {21, 3, 15, 9},
    {21, 3, 15, 9},
    {22, 3, 16, 9},
    {22, 3, 16, 10},
    {23, 3, 16, 10},
    {23, 3, 17, 10},
    {24, 3, 17, 10},
    {24, 3, 17, 10},
    {25, 4, 18, 11},
    {25, 4, 18, 11},
    {25, 4, 18, 11},
    {26, 4, 18, 11},
    {26, 4, 19, 11},
    {27, 4, 19, 11},
    {27, 4, 19, 12},
    {28, 4, 20, 12},
    {28, 4, 20, 12},
    {28, 4, 20, 12},
    {29, 4, 21, 12},
    {29, 4, 21, 13},
    {30, 4, 21, 13},
    {30, 4, 22, 13},
    {31, 4, 22, 13},
    {31, 4, 22, 13},
    {32, 5, 23, 14},
    {32, 5, 23, 14},
    {32, 5, 23, 14},
    {33, 5, 23, 14},
    {33, 5, 24, 14},
    {34, 5, 24, 14},
    {34, 5, 24, 15},
    {35, 5, 25, 15},
    {35, 5, 25, 15},
    {35, 5, 25, 15},
    {36, 5, 26, 15},
    {36, 5, 26, 16},
    {37, 5, 26, 16},
    {37, 5, 27, 16},
    {38, 5, 27, 16},
    {38, 5, 27, 16},
    {39, 6, 28, 17},
    {39, 6, 28, 17},
    {39, 6, 28, 17},
    {40, 6, 28, 17},
    {40, 6, 29, 17},
    {41, 6, 29, 17},
    {41, 6, 29, 18},
    {42, 6, 30, 18},
    {42, 6, 30, 18},
    {42, 6, 30, 18},
    {43, 6, 31, 18},
    {43, 6, 31, 19},
    {44, 6, 31, 19},
    {44, 6, 32, 19},
    {45, 6, 32, 19},
    {45, 6, 32, 19},
    {46, 7, 33, 20},
    {46, 7, 33, 20},
    {46, 7, 33, 20},
    {47, 7, 33, 20},
    {47, 7, 34, 20},
    {48, 7, 34, 20},
    {48, 7, 34, 21},
    {49, 7, 35, 21},
    {49, 7, 35, 21},
    {49, 7, 35, 21},
    {50, 7, 36, 21},
    {50, 7, 36, 22},
    {51, 7, 36, 22},
    {51, 7, 37, 22},
    {52, 7, 37, 22},
    {52, 7, 37, 22},
    {53, 8, 38, 23},
    {53, 8, 38, 23},
    {53, 8, 38, 23},
    {54, 8, 38, 23},
    {54, 8, 39, 23},
    {55, 8, 39, 23},
    {55, 8, 39, 24},
    {56, 8, 40, 24},
};

void errdiff(byte gray[IMG_H][IMG_W]);
